<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('正式服务商列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">

                        <ul>
                            <li>
                                <label style="width:80px;">服务商编号：</label>
                                <input type="text" name="agentNum"/>
                            </li>
                            <li>
                                <label style="width:80px;">服务商名称：</label>
                                <input type="text" name="agentName"/>
                            </li>
                            <li>
                                <label style="width:80px;">靓号：</label>
                                <input type="text" name="beautiful"/>
                            </li>
                            <li>
                                <label style="width:80px;">靓号名称：</label>
                                <input type="text" name="beautifulName"/>
                            </li>
                            <li>
                                <label style="width:80px;">登录账号：</label>
                                <input type="text" name="loginName"/>
                            </li>
                            <li>
                                <label style="width:80px;">服务商状态：</label>
                                <select name="agentStatus">
                                    <option value="">请选择</option>
                                    <option value="0">正常</option>
                                    <option value="5">服务商注销</option>
                                    <option value="6">已禁用</option>
                                </select>
                            </li>
                            <li>
                                <label style="width:80px;">服务商类型：</label>
                                <select name="saleType">
                                    <option value="0">服务商</option>
                                    <option value="1">业务员</option>
                                </select>
                            </li>
                            <li>
                                <label style="width:80px;">服务商档位：</label>
                                <select name="grade">
                                    <option value="">请选择</option>
                                    <option value="V1">V1</option>
                                    <option value="V2">V2</option>
                                    <option value="V3">V3</option>
                                    <option value="V4">V4</option>
                                    <option value="V5">V5</option>
                                    <option value="V6">V6</option>
                                    <option value="V7">V7</option>
                                    <option value="V8">V8</option>
                                    <option value="V9">V9</option>
                                    <option value="V10">V10</option>
                                </select>
                            </li>
                            <li>
                                <label style="width:80px;">扶持档位：</label>
                                <select name="supportLevel">
                                    <option value="">请选择</option>
                                    <option value="V1">V1</option>
                                    <option value="V2">V2</option>
                                    <option value="V3">V3</option>
                                    <option value="V4">V4</option>
                                    <option value="V5">V5</option>
                                    <option value="V6">V6</option>
                                    <option value="V7">V7</option>
                                    <option value="V8">V8</option>
                                    <option value="V9">V9</option>
                                    <option value="V10">V10</option>
                                </select>
                            </li>
                            <li class="select-time">
                                <label style="width:80px;">创建日期：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始日期" name="params[beginAddTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束日期" name="params[endAddTime]"/>
                            </li>
                            <li class="select-time">
                                <label style="width:80px;">扶持到期日：</label>
                                <input type="text" class="time-input" id="startTime1" placeholder="开始日期" name="params[beginDate]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime1" placeholder="结束日期" name="params[endDate]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-warning single disabled" onclick="changeStatus()" shiro:hasPermission="agentInfo:agentInfo:changeStatus">
                    <i class="fa fa-cog"></i> 启/禁用
                </a>
                <a class="btn btn-success single disabled" onclick="resetPwd()" shiro:hasPermission="agentInfo:agentInfo:resetPwd">
                    <i class="fa fa-key"></i> 重置密码
                </a>
                <a class="btn btn-success single disabled" onclick="sjAgent()" shiro:hasPermission="agentInfo:agentInfo:sjAgent">
                    <i class="fa fa-edit"></i> 查看上级
                </a>
                <a class="btn btn-success single disabled" onclick="xjAgent()" shiro:hasPermission="agentInfo:agentInfo:xjAgent">
                    <i class="fa fa-edit"></i> 查看下级
                </a>
                <a class="btn btn-success single disabled" onclick="onchageJs()" shiro:hasPermission="agentInfo:agentInfo:onchageJs">
                    <i class="fa fa-edit"></i> 分润冻结
                </a>
                <a class="btn btn-success single disabled" onclick="onchageProfit()" shiro:hasPermission="agentInfo:agentInfo:profit">
                    <i class="fa fa-edit"></i> 变更分润状态
                </a>
                <a class="btn btn-success single disabled" onclick="updateTaxStatus()" shiro:hasPermission="agentInfo:agentInfo:updateAgentTax">
                    <i class="fa fa-edit"></i> 设置计税状态
                </a>
                <a class="btn btn-success single disabled" onclick="updateAgentAll()" shiro:hasPermission="agentInfo:agentInfo:updateAgentAll">
                    <i class="fa fa-key"></i> 变更代理信息
                </a>
                <a class="btn btn-success single disabled" onclick="updateBankAgent()" shiro:hasPermission="agentInfo:agentInfo:updateBankAgent">
                    <i class="fa fa-edit"></i>变更代理结算
                </a>
                <a class="btn btn-success single disabled" onclick="insertCode()" shiro:hasPermission="agentInfo:agentInfo:insertCode">
                    <i class="fa fa-edit"></i> 申请靓号
                </a>
                <a class="btn btn-success single disabled" onclick="insertVm()" shiro:hasPermission="agentInfo:agentInfo:insertCode">
                    <i class="fa fa-edit"></i> 新增虚拟号
                </a>
                <a class="btn btn-success single disabled" onclick="upgrade()" shiro:hasPermission="agentInfo:agentInfo:upgrade">
                    <i class="fa fa-edit"></i> 提升档位
                </a>
                <!--<a class="btn btn-success single disabled" onclick="rainGrade()" shiro:hasPermission="agentInfo:agentInfo:rainGrade">
                    <i class="fa fa-edit"></i> 降级档位
                </a>-->
                <a class="btn btn-success single disabled" onclick="setGradeDelay()" shiro:hasPermission="agentInfo:agentInfo:setGradeDelay">
                    <i class="fa fa-edit"></i> 延长扶持
                </a>
                <a class="btn btn-success" onclick="setGradeEnd()" shiro:hasPermission="agentInfo:agentInfo:setGradeEnd">
                    <i class="fa fa-edit"></i> 设置扶持过期
                </a>
                <a class="btn btn-success single disabled" onclick="demotion()" shiro:hasPermission="agentInfo:agentInfo:demotion">
                    <i class="fa fa-edit"></i> 降级指定档位
                <a class="btn btn-warning" onclick="exportExcel()" shiro:hasPermission="agentInfo:agentInfo:exportExcel">
                    <i class="fa fa-edit"></i> 导出
                </a>
                <a class="btn btn-success single disabled" onclick="exportAgent()" shiro:hasPermission="agentInfo:agentInfo:exportAgent">
                    <i class="fa fa-download"></i> 导出信息
                </a>
                <a class="btn btn-success single disabled" onclick="agentMigrate()" shiro:hasPermission="agentInfo:agentInfo:agentMigrate">
                    <i class="fa fa-download"></i> 代理迁移
                </a>
                <a class="btn btn-primary single disabled" onclick="setPolicy()" shiro:hasPermission="agentInfo:agentInfo:setPolicy">
                    <i class="fa fa-edit"></i> 配置政策
                </a>
                <a class="btn btn-primary single disabled" onclick="findActInfo()" shiro:hasPermission="agentInfo:agentInfo:setPolicy">
                    <i class="fa fa-edit"></i> 政策详情
                </a>
                <a class="btn btn-primary single disabled" onclick="pushLevel()" shiro:hasPermission="agentInfo:agentInfo:setPolicy">
                    <i class="fa fa-edit"></i> 设置推送等级
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table" class="table text-nowrap"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var datas = [[${@dict.getType('agent_status')}]];
        var editFlag = [[${@permission.hasPermi('agentInfo:agentInfo:query')}]];
        var setPointFlag = [[${@permission.hasPermi('agentInfo:agentInfo:setPoint')}]];
        var removeFlag = [[${@permission.hasPermi('agentInfo:agentInfo:remove')}]];
        var prefix = ctx + "agentInfo/agentInfo";
        var accounts = ctx + "agentInfo/account";

        $(function() {
            var options = {
                url: prefix + "/list3",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                exportExcelUrl: prefix + "/exportExcel",
                exportAgent: prefix + "/exportAgent",
                clickToSelect:true,
                modalName: "服务商申请",
                columns: [{
                    radio: true
                },
                {
                    field: 'agentNum',
                    title: '服务商编号'
                },
                {
                    field: 'beautiful',
                    title: '靓号'
                },
                {
                    field: 'agentName',
                    title: '服务商名称'
                },
                {
                    field: 'beautifulName',
                    title: '靓号名称',
                    formatter:function (value, row, index) {
                        return $.table.tooltip(value,15);
                    }
                },
                {
                    field: 'areaName',
                    title: '区域',
                    formatter:function (value, row, index) {
                        return $.table.tooltip(value,5);
                    }
                },
                {
                    field: 'commissary',
                    title: '法人姓名'
                },
                {
                    field: 'showIdentitynum',
                    title: '身份证',
                    formatter:function (value, row, index) {
                        return $.table.tooltip(value,5);
                    }
                },
                {
                    field: 'linkPhone',
                    title: '联系电话'
                },
                {
                    field: 'status',
                    title: '服务商来源',
                    formatter:function(value,row,index){
                        if (value == '0'){
                            return "APP";
                        } else if (value == '1'){
                            return "平台";
                        }
                    }
                },
                {
                    field: 'agentStatus',
                    title: '状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'profitStatus',
                    title: '结算状态',
                    formatter: function (value, row, index) {
                        if (value == '0'){
                            return '<span style="color: green">正常</span>';
                        } else if (value == '1'){
                            return '<span style="color: red">关停</span>';
                        } else {
                            return '未知';
                        }
                    }
                },
                {
                    field: 'grade',
                    title: '档位'
                },
                {
                    field: 'supportLevel',
                    title: '扶持档位'
                },
                {
                    field: 'supportDate',
                    title: '到期时间'
                },
                {
                    field: 'gradeActDate',
                    title: '扶持到期日'
                },
                {
                    field: 'loginName',
                    title: '登录账号'
                },
                {
                    field: 'smName',
                    title: '销售经理',
                    formatter:function (value, row, index) {
                        return $.table.tooltip(value,4);
                    }
                },
                {
                    field: 'smName1',
                    title: '签约经理',
                    formatter:function (value, row, index) {
                        return $.table.tooltip(value,4);
                    }
                },
                {
                    field: 'beginValid',
                    title: '有效期(起始)',
                    formatter:function (value, row, index) {
                        return $.table.tooltip(value,5);
                    }
                },
                {
                    field: 'endValid',
                    title: '有效期(截止)',
                    formatter:function (value, row, index) {
                        return $.table.tooltip(value,5);
                    }
                },
                {
                    field: 'addName',
                    title: '添加人',
                    formatter:function (value, row, index) {
                        return $.table.tooltip(value,2);
                    }
                },
                {
                    field: 'localdate',
                    title: '添加日期',
                    formatter:function (value, row, index) {
                        return $.table.tooltip(value,5);
                    }
                },
                {
                    field: 'note',
                    title: '备注',
                    formatter:function (value, row, index) {
                        return $.table.tooltip(value,5);
                    }
                },
                {
                    field: 'agentNature',
                    title: '数据来源',
                    visible: false
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="query(\'' + row.agentNum + '\')"><i class="fa fa-edit"></i>查看服务商</a> ');
                        var more = [];
                        more.push("<a class='btn btn-default btn-xs " + setPointFlag + "' href='javascript:void(0)' onclick='setPoint(" + row.agentNum + ")'><i class='fa fa-check-square-o'></i>税点配置</a> ");
                        actions.push('<a tabindex="0" class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多操作</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /**
         * 查看政策
         */
        function findActInfo() {
            var agentNum = $.table.selectColumns("agentNum");
            var url = ctx + "agentInfo/agentActActive?agentNum=" + agentNum;
            $.modal.openTab("查看政策", url);
        }
        /**
         * 配置推送等级
         */
        function pushLevel() {
            var agentNum = $.table.selectColumns("agentNum");
            $.modal.open("配置推送等级",prefix + "/pushLevel/" + agentNum,'800','350');

        }

        function changeStatus() {
            var agentNum = $.table.selectColumns("agentNum");
            $.modal.open("启用/禁用服务商",prefix + "/changeStatus/" + agentNum,'800','350');
        }
     /*   function cancelAgent() {
            var agentNum = $.table.selectColumns("agentNum");
            $.modal.open("注销服务商",prefix + "/cancelAgent/" + agentNum,'800','350');
        }*/
        /* 用户管理-重置密码 */
        function resetPwd() {
            var agentNum = $.table.selectColumns("agentNum");
            $.modal.open("重置密码", prefix + '/resetPwd/' + agentNum, '800', '300');
        }

        /* 变更服务商信息 */
        function updateAgentAll() {
            var agentNum = $.table.selectColumns("agentNum");
            $.modal.open("变更服务商信息", prefix + '/updateAgentAll/' + agentNum, '800', '400');
        }
        function query(agentNum) {

            //如果是移动端，就使用自适应大小弹窗
            var width=1200;
            var height=$(window).height() - 50;
            if ($.common.isMobile()) {
                width = 'auto';
                height = 'auto';
            }
            var url = prefix + "/findInfo?agentNum=" + agentNum;
            var btn = ['关闭'];
            var options = {
                title: '查看服务商',
                width: width,
                height: height,
                url: url,
                btn: btn,
                yes:function(index){
                    layer.close(index);
                }
            };
            $.modal.openOptions(options);
        }

        function setPoint(agentNum) {
            $.modal.open("设置税点", prefix + '/setPoint?agentNum=' + agentNum, '800','600');
        }

        //上级代理
        function sjAgent(agentNum) {
            var agentNum = $.table.selectColumns("agentNum");
            $.modal.openTab("上级代理",prefix + '/supervisorAgentInfo?agentNum=' + agentNum);
        }

        //下级代理
        function xjAgent(agentNum) {
            var agentNum = $.table.selectColumns("agentNum");
            $.modal.openTab("下级代理",prefix + '/supervisorAgentInfo?belongAgent=' + agentNum)
        }


        function onchageJs() {
            var agentNum = $.table.selectColumns("agentNum");
            $.modal.open("修改结算", prefix + '/onchageJs/' + agentNum, '850', '350');
        }
        function onchageProfit() {
            var agentNum = $.table.selectColumns("agentNum");
            $.modal.open("变更分润状态", prefix + '/onchageProfit/' + agentNum, '850', '350');
        }
        function updateTaxStatus() {
            var agentNum = $.table.selectColumns("agentNum");
            $.modal.open("设置计税状态", prefix + '/updateTaxStatus/' + agentNum, '850', '350');
        }

        function insertCode() {
            var agentNum = $.table.selectColumns("agentNum");
            $.modal.open("申请靓号", prefix + '/insertCode/' + agentNum, '850', '400');
        }
        function insertVm() {
            var agentNum = $.table.selectColumns("agentNum");
            $.modal.open("新增虚拟号", prefix + '/insertVm/' + agentNum, '850', '400');
        }


        /**
         * 导出服务商信息
         */
        // 导出数据
        function exportExcel(formId) {
            table.set();
            $.modal.confirm("确定导出所有" + table.options.modalName + "吗？", function() {
                var currentId = $.common.isEmpty(formId) ? $('form').attr('id') : formId;
                var params = $("#" + table.options.id).bootstrapTable('getOptions');
                var dataParam = $("#" + currentId).serializeArray();
                dataParam.push({ "name": "orderByColumn", "value": params.sortName });
                dataParam.push({ "name": "isAsc", "value": params.sortOrder });
                $.modal.loading("正在导出数据，请稍后...");
                $.post(table.options.exportExcelUrl, dataParam, function(result) {
                    if (result.code == web_status.SUCCESS) {
                        window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                    } else if (result.code == web_status.WARNING) {
                        $.modal.alertWarning(result.msg)
                    } else {
                        $.modal.alertError(result.msg);
                    }
                    $.modal.closeLoading();
                });
            });
        }

        /**
         * 延长扶持挡位日期
         */
        function setGradeDelay() {
            var agentNum = $.table.selectColumns("agentNum");
            $.modal.open("延长扶持挡位日期",prefix + "/setGradeDelay/" + agentNum,'800','400');
        }

        /**
         * 设置扶持活动过期日
         */
        function setGradeEnd() {
            $.modal.open("设置扶持活动过期",prefix + "/setGradeEnd",'800','400');
        }

        /**
         * 升级档位
         */
        function upgrade() {
            var agentNum = $.table.selectColumns("agentNum");
            $.modal.open("提升档位", prefix + "/dw?agentNum=" + agentNum, '1200', '650');
        }


        /**
         * 降级指定档位
         */
        function demotion() {
            var agentNum = $.table.selectColumns("agentNum");
            $.modal.open("降级指定档位", prefix + "/demotion?agentNum=" + agentNum, '1200', '650');
        }


        function addBalance(){
            var agentNum = $.table.selectColumns("agentNum");
            var agentName = $.table.selectColumns("agentName");
            if (agentNum.length == 0) {
                $.modal.alertWarning("请选择一条记录");
                return;
            }
            var url = accounts + "/addBalance?type=1&agentNum="+agentNum + "&agentName=" + agentName;
            $.modal.open("虚拟账户开户充值", url,800,450);

        }

        function exportAgent(){
            table.set();
            $.modal.confirm("导出代理信息为该代理本级及以下信息内容", function() {
                var agentNum = $.table.selectColumns("agentNum")[0];
                $.modal.loading("正在导出数据，请稍后...");
                $.post(table.options.exportAgent, agentNum, function(result) {
                    if (result.code == web_status.SUCCESS) {
                        window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                    } else if (result.code == web_status.WARNING) {
                        $.modal.alertWarning(result.msg)
                    } else {
                        $.modal.alertError(result.msg);
                    }
                    $.modal.closeLoading();
                });
            });
        }
        function agentMigrate() {
            //商户编号
            var agentNum = $.table.selectColumns("agentNum");
            $.modal.open("代理商迁移",prefix + "/agentMigrate?agentNum=" + agentNum,'1100','800');
        }


        function updateBankAgent() {
            var agentNum = $.table.selectColumns("agentNum");
            if ($.common.isEmpty(agentNum)) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            $.modal.open("修改结算银行",prefix + "/updateBankAgent/" + agentNum,'1200','600');
        }

        /**
         * 配置政策
         */
        function setPolicy() {
            var agentNum = $.table.selectColumns("agentNum");
            $.modal.open("配置政策", prefix + "/setPolicy?agentNum="+agentNum,"1000","550");
        }


    </script>
</body>
</html>
